//
//  ZHNavViewController.m
//  ZHLifeCircle
//
//  Created by user on 15/11/21.
//  Copyright © 2015年 heima. All rights reserved.
//

#import "ZHNavViewController.h"
#define NavItemEdgeLength 44

@implementation ZHNavViewController

- (void)viewDidLoad{
    
    UIView *navBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenNavBarHeight)];
    [self.view addSubview:navBarView];
    navBarView.backgroundColor = [UIColor redColor];
    
    UIButton *leftBtn =[[UIButton alloc] initWithFrame:CGRectMake(0, kScreenStatusBarHeight, NavItemEdgeLength, NavItemEdgeLength)];
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(backBtn) forControlEvents:UIControlEventTouchUpInside];
    self.leftBtn = leftBtn;
    [navBarView addSubview:leftBtn];
    
    UILabel *centralLabel = [[UILabel alloc] initWithFrame:CGRectMake(NavItemEdgeLength, kScreenStatusBarHeight, kScreenWidth - 2 * NavItemEdgeLength, NavItemEdgeLength)];
    centralLabel.textAlignment = NSTextAlignmentCenter;
    self.centralLabel = centralLabel;
    centralLabel.textColor = [UIColor whiteColor];
    [navBarView addSubview:centralLabel];
    
    UIButton *rightBtn = [[UIButton alloc] init];
    self.rightBtn = rightBtn;
    BOOL isLogin = YES;
    //判断是否已经登录
    if (isLogin) {
        rightBtn.frame = CGRectMake(CGRectGetMaxX(centralLabel.frame), kScreenStatusBarHeight, NavItemEdgeLength, NavItemEdgeLength);
        [rightBtn setBackgroundImage:[UIImage imageNamed:@"nav_user"] forState:UIControlStateNormal];
        //跳转到个人中心
        [rightBtn addTarget:self action:@selector(gotoSelfCenter) forControlEvents:UIControlEventTouchUpInside];
    }
    else{
        [rightBtn setTitle:@"登录/注册" forState:UIControlStateNormal];
        [rightBtn addTarget:self action:@selector(loginBtn) forControlEvents:UIControlEventTouchUpInside];
        [rightBtn sizeToFit];
    }
    [navBarView addSubview:rightBtn];
    
}

- (void)gotoSelfCenter{
}
- (void)backBtn{
}
- (void)loginBtn{
}

@end
